const RouterHook = require("../module/routerModule");
const {
    getCardInfo,
    getChangeCarInfo,
    getCardList,
    getReverseImage
} = require("../service/carInfo");
const {
    AssertUtils
} = require("../util/utils");

const router = RouterHook()
/**
 * @swagger
 * /api/carInfo/:
 *    get:
 *      tags:
 *      - 汽车接口
 *      summary: 用户汽车列表
 *      produces:
 *      - application/json
 *      responses:
 *        200:
 *          description: 返回汽车列表
 *          schema:
 *            type: Array
 *        500:
 *          description: 账号密码错误
 * */
router.get("/", async (ctx, netx) => {
    const {
        id
    } = ctx.state.current
    const {
        pageNum,
        pageSize
    } = ctx.request.query
    const result = await getCardInfo(id, pageNum, pageSize)
    ctx.result.success(result)
})
router.get("/list", async (ctx, netx) => {
    const {
        id
    } = ctx.state.current
    const result = await getCardByUserList(id)
    ctx.result.success(result)
})
/**
 * @swagger
 * /api/carInfo/change:
 *    post:
 *      tags:
 *      - 汽车接口
 *      summary: 修改汽车状态
 *      produces:
 *      - application/json
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              type: object
 *              required:
 *                - id
 *              properties:
 *                fan:
 *                  type: string
 *                  default: 0
 *                  description: 风扇风速状态 
 *                car_lock:
 *                  type: string
 *                  default: 0
 *                  description: 车锁信息 0:关 1：开
 *                window_trunk:
 *                  type: string
 *                  default: 0
 *                  description: 车窗后备厢  1：开  0:关
 *                flash_light:
 *                  type: string
 *                  default: 0
 *                  description: 闪灯   1：开  0:关
 *                stir_up_trouble:
 *                  type: string
 *                  default: 0
 *                  description: 点火   1：开  0:关
 *                air_conditioning:
 *                  type: string
 *                  default: 0
 *                  description: 空调状态   1：开  0:关
 *                flashingLights_whistling:
 *                  type: string
 *                  default: 0
 *                  description: 闪灯呜笛    1：开  0:关
 * 
 *      responses:
 *        200:
 *          description: 返回Token
 *          schema:
 *            type: object
 *            properties:
 *              token:
 *                type: string
 *                default: xxxxxxxxxxxxxxxxxxx
 *        500:
 *          description: 用户名不能为空
 * */
router.get("/change", async (ctx, netx) => {
    const {
        id
    } = ctx.state.current
    // const data = ctx.request.body
    const data = ctx.request.query

    AssertUtils.StringNotEmpty(data.id, "id不能为空")
    const result = await getChangeCarInfo(data, id)
    ctx.result.success(result)
})
router.get('/reverseImage', (ctx, netx) => {
    const result = getReverseImage()
    ctx.result.success(result)
}).noAuth()

module.exports = router